package org.jeecg.modules.basic.plant.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.basic.plant.entity.WmsSapWarehouseMap;
import org.jeecg.modules.basic.plant.service.IWmsSapWarehouseMapService;
import org.jeecg.modules.basic.saplocation.service.IWmsSapLocationService;
import org.jeecg.modules.basic.warehouse.service.IWmsBasicWarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
 * @Description: 仓库和sap库位对照信息
 * @Author: jeecg-boot
 * @Date: 2023-10-16
 * @Version: V1.0
 */
@Api(tags = "仓库和sap库位对照信息")
@RestController
@RequestMapping("/plant/wmsSapWarehouseMap")
@Slf4j
public class WmsSapWarehouseMapController extends JeecgController<WmsSapWarehouseMap, IWmsSapWarehouseMapService> {
    @Autowired
    private IWmsSapWarehouseMapService wmsSapWarehouseMapService;

    @Autowired
    private IWmsBasicWarehouseService wmsBasicWarehouseService;
    @Autowired
    private IWmsSapLocationService iWmsSapLocationService;

    /**
     * 分页列表查询
     *
     * @param wmsSapWarehouseMap
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @ApiOperation(value = "仓库和sap库位对照信息-分页列表查询", notes = "仓库和sap库位对照信息-分页列表查询")
    @GetMapping(value = "/list")
    public Result<Page<WmsSapWarehouseMap>> queryPageList(WmsSapWarehouseMap wmsSapWarehouseMap,
                                                           @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                           @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                           HttpServletRequest req) {
        Result<Page<WmsSapWarehouseMap>> result = new Result<Page<WmsSapWarehouseMap>>();
        Page<WmsSapWarehouseMap> pageList = new Page<WmsSapWarehouseMap>(pageNo, pageSize);
        pageList = wmsSapWarehouseMapService.listByPage(pageList, wmsSapWarehouseMap);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    /**
     * 添加
     *
     * @param wmsSapWarehouseMap
     * @return
     */
    @AutoLog(value = "仓库和sap库位对照信息-添加")
    @ApiOperation(value = "仓库和sap库位对照信息-添加", notes = "仓库和sap库位对照信息-添加")
    @RequiresPermissions("plant:wms_sap_warehouse_map:add")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody WmsSapWarehouseMap wmsSapWarehouseMap) {
        wmsSapWarehouseMapService.resave(wmsSapWarehouseMap);
        return Result.OK("添加成功！");
    }

    /**
     * 编辑
     *
     * @param wmsSapWarehouseMap
     * @return
     */
    @AutoLog(value = "仓库和sap库位对照信息-编辑")
    @ApiOperation(value = "仓库和sap库位对照信息-编辑", notes = "仓库和sap库位对照信息-编辑")
    @RequiresPermissions("plant:wms_sap_warehouse_map:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> edit(@RequestBody WmsSapWarehouseMap wmsSapWarehouseMap) {
        wmsSapWarehouseMapService.updatePlant(wmsSapWarehouseMap);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "仓库和sap库位对照信息-通过id删除")
    @ApiOperation(value = "仓库和sap库位对照信息-通过id删除", notes = "仓库和sap库位对照信息-通过id删除")
    @RequiresPermissions("plant:wms_sap_warehouse_map:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        wmsSapWarehouseMapService.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "仓库和sap库位对照信息-批量删除")
    @ApiOperation(value = "仓库和sap库位对照信息-批量删除", notes = "仓库和sap库位对照信息-批量删除")
    @RequiresPermissions("plant:wms_sap_warehouse_map:deleteBatch")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.wmsSapWarehouseMapService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "仓库和sap库位对照信息-通过id查询")
    @ApiOperation(value = "仓库和sap库位对照信息-通过id查询", notes = "仓库和sap库位对照信息-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<WmsSapWarehouseMap> queryById(@RequestParam(name = "id", required = true) String id) {
        WmsSapWarehouseMap wmsSapWarehouseMap = wmsSapWarehouseMapService.getById(id);
        if (wmsSapWarehouseMap == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(wmsSapWarehouseMap);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param wmsSapWarehouseMap
     */
    @RequiresPermissions("plant:wms_sap_warehouse_map:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, WmsSapWarehouseMap wmsSapWarehouseMap) {
        return super.exportXls(request, wmsSapWarehouseMap, WmsSapWarehouseMap.class, "仓库和sap库位对照信息");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @RequiresPermissions("plant:wms_sap_warehouse_map:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, WmsSapWarehouseMap.class);
    }

}
